﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ClubController : ControllerBase
    {
        private readonly DZJDBcontext db;
        /// <summary>
        /// 数据库
        /// </summary>

        public ClubController(DZJDBcontext context)
        {
            db = context;
        }
        [HttpGet]
        public List<EM_Club> GetAll()
        {
            //select * from EM_Club 查找
            return db.EM_Club.ToList();
        }
        [HttpPost]
        public bool Add(EM_Club em_Club)
        {
            //sql insert into  set 活动人数增加
            db.EM_Club.Add(em_Club);

            int result = db.SaveChanges();
            return result > 0 ? true : false;
        }

        [HttpDelete]
        public bool Delete(Guid ID)
        {
            EM_Club? em_Club = new EM_Club();
            em_Club = db.EM_Club.Where(a => a.ID == ID).SingleOrDefault();

            int result = 0;
            if (em_Club != null)
            {
                //sql update...
                db.EM_Club.Remove(em_Club);
                result = db.SaveChanges();
            }



            return result > 0 ? true : false;
        }
    }
}
